<!DOCTYPE html>
<meta charset="utf-8" />
<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />

<div class="search_panel">
<form action="" id="casSearchForm" method="post" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">订单号:</label>
							<div class="search_input">
								<input id="casOrdNo" type="text" name="casOrdNo" placeholder="请输入订单号">
							</div>
						</div>
					<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户编号:</label>
							<div class="search_input">
								<input id="custId" type="text" name="custId" placeholder="请输入商户编号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户名称:</label>
							<div class="search_input">
								<input id="custName" type="text" name="custName" placeholder="请输入商户名称">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户手机:</label>
							<div class="search_input">
								<input id="usrMobile" type="text" name="usrMobile"
									placeholder="请输入商户手机">
							</div>
						</div>
						<!-- <div class="search_elm" style="margin-left: 0px">
							<label class="label_search">合作商编号:</label>
							<div class="search_input">
								<input id="agentId" type="text" name="agentId" placeholder="请输入商户名称">
							</div>
						</div> -->
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">结算卡号:</label>
							<div class="search_input">
								<input id="cardNo" type="text" name="cardNo" placeholder="请输入银行卡号">
							</div>
						</div>
						
						<!-- <div class="search_elm" style="margin-left: 0px">
							<label class="label_search">开户行:</label>
							<div class="search_input">
								<input id="bankcode" type="text" name="bankcode" placeholder="请输入开户行">
							</div>
						</div> -->
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">订单状态:</label>
							<div class="search_input">
							<select 
								rel="obj.CASORDSTATUS"
								location="local" 
								 name="ordStatus" 
								 id="search_paystatus" 
								  style="width: 120px;vertical-align:middle;">
								  <option value="">---选择---<option>
						 </select>
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">提现类型:</label>
							<div class="search_input">
							<select 
								rel="obj.CASTPYE"
								location="local" 
								 name="casType" 
								 id="search_casType" 
								  style="width: 120px;vertical-align:middle;">
								  <option value="">---选择---<option>
						 </select>
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">订单审核状态:</label>
							<div class="search_input">
								<select 
									rel="obj.CASAUDITSTATUS"
									location="local" 
									 name="casAudit" 
									 id="search_casAudit" 
									  style="width: 120px;vertical-align:middle;">
									  <option value="">---选择---<option>
							 	</select>
							</div>
						</div>
						
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">提现渠道:</label>
							<div class="search_input">
								<select 
									rel="obj.CHANNELCODE"
									location="local" 
									name="casChannel" 
									id="casChannel" 
									valName="cooporgNo"
									textName="coopname"
									style="width: 120px;vertical-align:middle;">
									 <option value="">---选择---</option>
								</select>
							</div>
						</div>
						
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">代付审核状态:</label>
							<div class="search_input">
							<select 
								rel="obj.CASAUDITSTATUS"
								location="local" 
								 name="casAuditStatus" 
								 id="search_casAuditStatus" 
								  style="width: 120px;vertical-align:middle;">
								  <option value="">---选择---<option>
						 </select>
							</div>
						</div>
						
						<div class="search_elm" style="margin-left: 0px;margin-right: 15px;width: 280px;">
						    <label class="label_search" for="userName">订单时间:</label> 
							<div class="input-group">
									<input type="text" class="form-control date-picker" name="sdate" id="prdDateStart"  placeholder="起始日期"  data-date-format="yyyy-mm-dd" />
									<span class="input-group-addon">
										<i class="fa fa-exchange"></i>
									</span>
									<input type="text" class="form-control date-picker" name="edate" id="prdDateEnd"  placeholder="结束日期"  data-date-format="yyyy-mm-dd"/>
							  </div>
						</div>
						
						<div class="search_elm">
							<button class="btn btn-small btn_search" type="submit" title="搜索" onclick="searchCount()">
								搜索
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div style="display: block;" class="widget-body " id="total">
		
	</div>
	</form>
	
	
	<div class="row">
		<div class="col-xs-12">
			<table id="grid-table"></table>
			<div id="grid-pager"></div>
			
			<div style="margin-top: 10px">
			<span id="auth_btn">
				<a  class="btn btn-small btn-info" onclick="reportCasOrder();">导出提现订单</a>
				<a  class="btn btn-small btn-info" onclick="updateAuditStatus('1');">允许代付</a>
				<a  class="btn btn-small btn-info" onclick="updateAuditStatus('2');">拒绝代付</a>
				<a  class="btn btn-small btn-warning" onclick="settleOver(1)">清算完成</a>
				<a  class="btn btn-small btn-warning" onclick="casByChannel('ZFPAY001','')">发起结算(中付)</a>
				<!-- <a  class="btn btn-small btn-warning" onclick="casByChannel('ZFPAY001','01')">发起T1结算(中付)</a> -->
				</span>
				 <span id="paging_bar" style="float: right"> </span>
			</div>
			<!-- PAGE CONTENT ENDS -->
		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->

	<!-- page specific plugin scripts -->
	<script type="text/javascript">
	var jqGrid;
	jQuery(function($) {
		var grid_selector = "#grid-table";
		var pager_selector = "#grid-pager";

		$(window).on(
				'resize.jqGrid',
				function() {
					$(grid_selector).jqGrid('setGridWidth',$(".page-content").width());
				})
		var parent_column = $(grid_selector).closest('[class*="col-"]');
		$(document).on(
				'settings.ace.jqGrid',
				function(ev, event_name, collapsed) {
					if (event_name === 'sidebar_collapsed'|| event_name === 'main_container_fixed') {
						setTimeout(function() {
							$(grid_selector).jqGrid('setGridWidth',parent_column.width());
						}, 0);
					}
				})
		jQuery(grid_selector).jqGrid({
			url : "mpomng/prdInf/casPrdList.do",
			datatype : "json",
			height : '100%',
			width : '100%',
			colNames : [ '订单号','收款订单号','商户编号  ','商户名称','订单时间','订单状态','提现类型','订单审核状态','线上代付审核状态','审核描述','订单金额','费率类型','手续费','服务费','到账金额','支付银行卡号','支付银行名称','结算银行卡号','结算银行名称','提现描述','审核人','提现渠道编号','完成时间','操作' ],
			colModel : [   {name : 'casOrdNo',        index : 'casOrdNo',        width : '90px',sortable:false}, 
						     {name : 'prdOrdNO',        index : 'prdOrdNO',        width : '150px',sortable:false }, 
						     {name : 'custId',        index : 'custId',        width : '130px',sortable:false }, 
						     {name : 'custName',        index : 'custName',        width : '60px',sortable:false },
						     {name : 'casDate',        index : 'casDate',        width : '135px',sortable:false,formatter : gridFormatByDate },
						     {name : 'ordStatus',        index : 'ordStatus',        width : '80px',sortable:false ,ditcKey:'CASORDSTATUS' ,formatter : gridFormatByDict },
						     {name : 'casType',        index : 'casType',        width : '80px',sortable:false,ditcKey : 'CASTPYE',formatter : gridFormatByDict },
						     {name : 'casAudit',        index : 'casAudit',        width : '80px',sortable:false ,ditcKey:'CASAUDITSTATUS' ,formatter : gridFormatByDict },
						     {name : 'casAuditStatus',        index : 'casAuditStatus',        width : '100px',sortable:false ,ditcKey:'CASAUDITSTATUS' ,formatter : gridFormatByDict },
						     {name : 'casAuditDes',        index : 'casAuditDes',        width : '100px',sortable:false ,ditcKey:'CASAUDITSTATUS' ,formatter : gridFormatByDict },
						     {name : 'ordAmt',        index : 'ordAmt',        width : '80px',sortable:false }, 
						     {name : 'rateType',        index : 'rateType',        width : '80px',sortable:false ,ditcKey:'RATETYPE', formatter:gridFormatByDict }, 
						     {name : 'fee',        index : 'fee',        width : '60px',sortable:false } ,
						     {name : 'serviceFee',        index : 'serviceFee',        width : '70px',sortable:false } ,
						     {name : 'netrecAmt',        index : 'netrecamt',        width : '90px',sortable:false } ,
						     {name : 'payCardNo',        index : 'payCardNo',        width : '150px',sortable:false } ,
						     {name : 'payIssNam',        index : 'payIssNam',        width : '100px',sortable:false } ,
						     {name : 'cardNo',        index : 'cardNo',        width : '150px',sortable:false } ,
						     {name : 'issNam',        index : 'issNam',        width : '100px',sortable:false } ,
						     {name : 'casDesc',        index : 'casDesc',        width : '150px',sortable:false } ,
						     {name : 'auditName',        index : 'auditName',        width : '120px',sortable:false } ,
						     {name : 'casChannel',        index : 'casChannel',        width : '100px',sortable:false } ,
						     {name : 'sucDate',        index : 'sucDate',        width : '130px',sortable:false,formatter : gridFormatByDate} ,
						     {name : '',        index : '',        width : '50px',sortable:false,formatter:operateEdit} 
			            ],
			viewrecords : true,
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			altRows : true,

			shrinkToFit : false,
			multiselect : true,//设置行可多选的 
			multiboxonly : true,//

			loadComplete : function() {
				var table = this;
				setTimeout(function() {
					//加载分页
					initPagingBar(grid_selector);
				}, 0);
			},
			beforeRequest : function() {//请求之前执行
				jqGrid = this;
			},
		});
		$(window).triggerHandler('resize.jqGrid');

		$(document).one('ajaxloadstart.page', function(e) {
			$(grid_selector).jqGrid('GridUnload');
			$('.ui-jqdialog').remove();
		});
	
		
		
	 	function operateEdit(cellvalue, options, rowObject){//定义button按钮
			var button = "<div class=\"hidden-sm hidden-xs btn-group\">";  
				button += "<button class='btn btn-xs btn-warning' onclick='casDetails(\""+rowObject["casOrdNo"]+"\")'"   
				 +"title='详细信息查看'>详细</button>";
			return button;
		};
	});
	
	
	function createDetailsBtn (cellvalue, options, rowObject){
		var button = "";  
		button += "<a class='pointer' onclick='casDetails(\""+rowObject["casOrdNo"]+"\")'"   
		 +"title='"+cellvalue+"'>"+cellvalue+"</a>";
		return button;
	}
	
	function casDetails(casOrdNo) {
		 if(!casOrdNo || casOrdNo.length<=0){
			msg.alert("警告", "当前没有选择数据项！", "error");
			return;
		}
		var scrWidth = document.body.scrollWidth;
		openDialog({
			dialogId : 'dlg-agentEdit',
			title : '收款订单详情',
			pageUrl :'mpomng/prdInf/casDetailsView.do',
			dataUrl : 'mpomng/prdInf/casDetails.do',
			width : '80%',
		    height:'80%',
			dataParam : {
				casOrdNo : casOrdNo
			},
			dataName : 'obj,map'//表单数据存储对象名称

		}); 
		
	}
	
	
	  $(document).ready(function(){
		 searchCount();
	
	 });
	
	function searchCount(){
		 $(document).ready(function(){
			 $.ajax({
					type : "post",
					url : "mpomng/prdInf/casCount.do",
					data:$("#casSearchForm").serialize(),
					dataType : 'json',
					async:true,
					success : function(result) {
						if (result.rspcod != 200) {
							msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
						} else {
							var count=result.obj.cntNum;
							var txamt=result.obj.cntOrdAmt;
							var fee=result.obj.cntFee;
							var serviceFee = result.obj.cntServiceFee;
							if(!count){
								count="0";
							}
							if(!txamt){
								txamt="0";
							}
							if(!fee){
								fee="0";
							}
							if(!serviceFee){
								serviceFee="0";
							}
							var html="";
							html+="汇总笔数和金额:["+count+"]笔  |  [" +txamt+ "]元  "
							html+="&nbsp;&nbsp;&nbsp;&nbsp;";
							html+="手续费总额:["+fee+"]元  服务费总额:["+serviceFee+"]";
							$("#total").html(html);
							
						}
					},
					error : function(XMLHttpRequest, textStatus) {
						msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
					}
				});
		

	});
		
	}
	
	function reportData_02_check() {
		var ch = true;
		$.ajax({
			type : "post",
			url : "mpomng/prdInf/ordStatusCount.do",
			data : {
				"ordStatus" : "01",
				"casType" : "00",
				"casAudit": "1"
			},
			dataType : 'json',
			async : false,
			success : function(result) {
				if (result.obj == 0) {
					ch = false;
				} else {
				}
			},
			error : function(XMLHttpRequest, textStatus) {
				msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
						+ textStatus, 'error');
			}
		});
		return ch;
	}
	
	function reportData_07_check() {
		var ch = true;
		var data = getFormParams($("#casSearchForm"));
		data['ordStatus'] = "01";
		data['casType'] = "01";
		data['casAudit'] = "1";
		$.ajax({
			type : "post",
			url : "mpomng/prdInf/ordStatusCount.do",
			data : data,
			dataType : 'json',
			async : false,
			success : function(result) {
				if (result.obj == 0) {
					ch = false;
				} else {
				}
			},
			error : function(XMLHttpRequest, textStatus) {
				msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
						+ textStatus, 'error');
			}
		});
		return ch;
	}
	
	
	
	function reportData_02(chl){
		if(reportData_02_check()==false){
			msg.alert("警告", "没有要清算的订单信息！", "error");
			return false;
		}else{
			var casOrdNo=$("#casOrdNo").val();
			var custId=$("#custId").val();
			var custName=$("#custId").val();
			var cardNo=$("#custName").val();
			var search_paystatus=$("#search_paystatus").val();
			var sdate=$("#prdDateStart").val();
			var edate=$("#prdDateEnd").val(); 
			
			var querycon = {"server":"02",
					"casOrdNo":casOrdNo,
					"custId":custId,
					"custName":custName,
					"cardNo":cardNo,
					"ordStatus":"01",
					"prdDateStart":sdate,
					"prdDateEnd":edate,
					"casType":"00",
					"stmChl":chl
					};
			report(querycon);
		}
		
	}
	
	function reportData_07(chl){
		if(reportData_07_check()==false){
			msg.alert("警告", "没有要清算的订单信息！", "error");
			return false;
		}
		/* var casOrdNo=$("#casOrdNo").val();
		var custId=$("#custId").val();
		var custName=$("#custId").val();
		var cardNo=$("#custName").val();
		var search_paystatus=$("#search_paystatus").val();
		var sdate=$("#prdDateStart").val();
		var edate=$("#prdDateEnd").val();  */
		
		var data = getFormParams($("#casSearchForm"));
		data["server"] = "07";
		data["casType"] = "01";
		data['ordStatus'] = "01";
		data['casAudit'] = "1";
		data['stmChl'] = chl;//结算渠道，用来对应导出格式
		
/* 		var querycon = {"server":"07",
				"casOrdNo":casOrdNo,
				"custId":custId,
				"custName":custName,
				"cardNo":cardNo,
				"ordStatus":"01",
				"prdDateStart":sdate,
				"prdDateEnd":edate,
				"casType":"01"
				};
 */		report(data);
		
	}
	
	function settleOver(type) {
		var url = "";
		var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
		if (rows.length == 0) {
			msg.alert("警告", "当前没有选择数据项！", "warn");
			return;
		}
		var casOrdNos = "";
		for (var i = 0; i < rows.length; i++) {
			/* if($('#grid-table').jqGrid('getRowData',rows[i]).ordStatus!='清算中'){
				msg.alert("警告", "只能设置清算中的订单！", "warn");
				return;
			} */
			　casOrdNos += $('#grid-table').jqGrid('getRowData',rows[i]).casOrdNo + ",";
		}
		casOrdNos = casOrdNos.substring(0, casOrdNos.lastIndexOf(","));
		var message = "";
		if(type == "1"){
			message = "确定清算完成此订单吗？"
			url = "mpomng/cas/settleOver.do?casOrdNos=" + casOrdNos;
		}else{
			message = "确定清算失败此订单吗？"
			url = "mpomng/cas/settleFalse.do?casOrdNos=" + casOrdNos;
		}
		msg.confirm({title:'确认',position:'center',msg:message,call:function(ok){
			if(ok){
				$.ajax({
					type : "post",
					url : url,
					dataType : 'json',
					success : function(result) {
						if (result.rspcod != 200) {
							msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
						} else {
							msg.alert("提示", result.rspmsg, 'correct');
							$("#grid-table").trigger("reloadGrid");
						}
					},
					error : function(XMLHttpRequest, textStatus) {
						msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
					}
				});
			}
		}});
		
		}
	
	function reportCasOrder(){
		msg.confirm({title:'确认',position:'center',msg:'您确定要导出提现数据吗？',call:function(ok){
			var data = getFormParams($("#casSearchForm"));
			if(ok){
				$.ajax({
					type : "post",
					url : 'mpomng/cas/reportCasOrder.do',
					dataType : 'json',
					data : data,
					success : function(result) {
						if (result.rspcod != 200) {
							msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
						} else {
							msg.alert("提示", result.rspmsg, 'correct');
							//$("#grid-table").trigger("reloadGrid");
						}
					},
					error : function(XMLHttpRequest, textStatus) {
						msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
					}
				});
			}
		}});
	}
	
	function casOrdSyn(){
		$.ajax({
			type : "post",
			url : 'mpomng/cas/casOrdSyn.do',
			dataType : 'json',
			success : function(result) {
				if (result.rspcod != 200) {
					msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
				} else {
					msg.alert("提示", result.rspmsg, 'correct');
					//$("#grid-table").trigger("reloadGrid");
				}
				$("#grid-table").trigger("reloadGrid");
			},
			error : function(XMLHttpRequest, textStatus) {
				msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
			}
		});
	}
	
	function casByChannel(casChannel,casType){
		var url = "";
		var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
		if (rows.length == 0) {
			msg.alert("警告", "当前没有选择数据项！", "warn");
			return;
		}
		var casOrdNos = "";
		for (var i = 0; i < rows.length; i++) {
			/* if($('#grid-table').jqGrid('getRowData',rows[i]).ordStatus!='清算中'){
				msg.alert("警告", "只能设置清算中的订单！", "warn");
				return;
			} */
			　casOrdNos += $('#grid-table').jqGrid('getRowData',rows[i]).casOrdNo + ",";
		}
		casOrdNos = casOrdNos.substring(0, casOrdNos.lastIndexOf(","));
		msg.confirm({title:'确认',position:'center',msg:'发起结算会通过线上代付直接转账到客户账户，您确定要清算订单吗？',call:function(ok){
			if(ok){
				$.ajax({
					type : "post",
					url : 'mpomng/cas/orderWithdrawal.do',
					dataType : 'json',
					data : {'casOrdNos':casOrdNos,'casChannel':casChannel,'casType':casType},
					success : function(result) {
						if (result.rspcod != 200) {
							msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
						} else {
							msg.alert("提示", result.rspmsg, 'correct');
						}
						$("#grid-table").trigger("reloadGrid");
					},
					error : function(XMLHttpRequest, textStatus) {
						msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
					}
				});
			}
		}});
	}
	
	function updateAuditStatus(auditStatus){
		var url = "";
		var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
		if (rows.length == 0) {
			msg.alert("警告", "当前没有选择数据项！", "warn");
			return;
		}
		var casOrdNos = "";
		for (var i = 0; i < rows.length; i++) {
			/* if($('#grid-table').jqGrid('getRowData',rows[i]).ordStatus!='清算中'){
				msg.alert("警告", "只能设置清算中的订单！", "warn");
				return;
			} */
			　casOrdNos += $('#grid-table').jqGrid('getRowData',rows[i]).casOrdNo + ",";
		}
		casOrdNos = casOrdNos.substring(0, casOrdNos.lastIndexOf(","));
		var msgStr = "";
		if(auditStatus == "1"){//通过
			msgStr = "您确定要允许选中的订单进行线上代付吗";
		}else if(auditStatus == "2"){
			msgStr = "您确定要拒绝选中的订单进行线上代付吗";
		}else{
			msg.alert("警告", "审核状态无效!", "warn");
			return;
		}
		msg.confirm({title:'确认',position:'center',msg:msgStr,call:function(ok){
			if(ok){
				$.ajax({
					type : "post",
					url : 'mpomng/cas/updateAuditStatus.do',
					dataType : 'json',
					data : {'casOrdNos':casOrdNos,'auditStatus':auditStatus},
					success : function(result) {
						if (result.rspcod != 200) {
							msg.alert("错误", result.rspmsg + " 错误代码："+ result.rspcod, 'error');
						} else {
							msg.alert("提示", result.rspmsg, 'correct');
						}
						$("#grid-table").trigger("reloadGrid");
					},
					error : function(XMLHttpRequest, textStatus) {
						msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
					}
				});
			}
		}});
	}
	</script>